from jobboard.models import *
from django.contrib.auth.models import User
from django import forms
import re

class RegistrationForm(forms.Form):

	first_name = forms.CharField(
		label=u'First Name',
		max_length=30,
		error_messages={'required': 'Please enter your first name'},
	)

	last_name = forms.CharField(
		label=u'Last Name',
		max_length=30,
		error_messages={'required': 'Please enter your last name'},
	)
	
	email = forms.EmailField(
		label=u'Email',
		error_messages={'required': 'Please enter your email address'},
	)

	username = forms.CharField(
		label=u'Username',
		max_length=30,
		error_messages={'required': 'Please enter your username'},
	)

	password1 = forms.CharField(
		label=u'Password',
		widget=forms.PasswordInput(),
		error_messages={'required': 'Please enter a password'},
	)
	password2 = forms.CharField(
		label=u'Password (Again)',
		widget=forms.PasswordInput(),
		error_messages={'required': 'Please enter the same password as above'},
	)
		
	address1 = forms.CharField(
		label=u'Address1',
		max_length=200,
		error_messages={'required': 'Please enter your street address'},
	)
	
	address2 = forms.CharField(
		label=u'Address2',
		required=False,
		max_length=200,
	)
	
	city = forms.CharField(
		label=u'City',
		max_length=200,
		error_messages={'required': 'Please enter which city your address corresponds to'},
	)
	
	state = forms.CharField(
		label=u'State / Territory',
		max_length=200,
		error_messages={'required': 'Please enter which state your address corresponds to'},
	)
		
	postalcode = forms.IntegerField(
		label=u'Postal Code',
		error_messages={'required': 'Please enter the postal code your address corresponds to'},
	)

	country = forms.CharField(
		label=u'Country',
		max_length=200,
		error_messages={'required': 'Please enter which country your address corresponds to'},
	)

	birthday = forms.DateField(
		label=u'Date of Birth (MM/DD/YYYY)',
		widget=forms.widgets.DateInput(format="%m/%d/%Y"),
		error_messages={'required': 'Please enter your date of birth'},
	)
	
	phone = forms.IntegerField(
		label=u'Phone Number',
		error_messages = {'required': 'Please enter your phone number'},
		required=False,
	)

	website = forms.URLField(
		label='Website',
		required=False
	)

	resume = forms.FileField(
		required=False,
		label=u'Upload a Resume:',
	)


	def clean_password2(self):
		if 'password1' in self.cleaned_data:
			password1 = self.cleaned_data['password1']
			password2 = self.cleaned_data['password2']
			if password1 == password2:
				return password2
		raise forms.ValidationError('Passwords do not match.')
	
	def clean_username(self):
		username = self.cleaned_data['username']
		if not re.search(r'^\w+$', username):
			raise forms.ValidationError('Username can only contain '
				'alphanumeric characters and the underscore.')
		try:
			User.objects.get(username=username)
		except User.DoesNotExist:
			return username
		raise forms.ValidationError('Username is already taken.')

class AccountForm(forms.Form):

	first_name = forms.CharField(
		label=u'First Name',
		max_length=30,
		error_messages={'required': 'Please enter your first name'},
	)

	last_name = forms.CharField(
		label=u'Last Name',
		max_length=30,
		error_messages={'required': 'Please enter your last name'},
	)
	
	email = forms.EmailField(
		label=u'Email',
		error_messages={'required': 'Please enter your email address'},
	)
		
	address1 = forms.CharField(
		label=u'Address1',
		max_length=200,
		error_messages={'required': 'Please enter your street address'},
	)
	
	address2 = forms.CharField(
		label=u'Address2',
		required=False,
		max_length=200,
	)
	
	city = forms.CharField(
		label=u'City',
		max_length=200,
		error_messages={'required': 'Please enter which city your address corresponds to'},
	)
	
	state = forms.CharField(
		label=u'State / Territory',
		max_length=200,
		error_messages={'required': 'Please enter which state your address corresponds to'},
	)
		
	postalcode = forms.IntegerField(
		label=u'Postal Code',
		error_messages={'required': 'Please enter the postal code your address corresponds to'},
	)

	country = forms.CharField(
		label=u'Country',
		max_length=200,
		error_messages={'required': 'Please enter which country your address corresponds to'},
	)

	birthday = forms.DateField(
		label=u'Date of Birth (MM/DD/YYYY)',
		widget=forms.widgets.DateInput(format="%m/%d/%Y"),
		error_messages={'required': 'Please enter your date of birth'},
	)
	
	phone = forms.IntegerField(
		label=u'Phone Number',
		error_messages = {'required': 'Please enter your phone number'},
	)
	
	website = forms.URLField(
		label='Website',
		required=False
	)

class ResumeForm(forms.Form):
	resume = forms.FileField(
		required=False,
		label=u'Upload a Resume:',
	)
	
class ProfileForm(forms.Form):
	view_email = forms.BooleanField(
		label=u'Show my email on my profile',
		required=False,
	)
	
	view_phone = forms.BooleanField(
		label=u'Show my phone number on my profile',
		required=False,
	)
	
	view_website = forms.BooleanField(
		label=u'Show a link to my website on my profile',
		required=False,
	)
	
	view_resume = forms.BooleanField(
		label=u'Show my resume on my profile',
		required=False,
	)

	view_address = forms.BooleanField(
		label=u'Show my street address on my profile',
		required=False,
	)

	view_city = forms.BooleanField(
		label=u'Show my city on my profile',
		required=False,
	)

	view_state = forms.BooleanField(
		label=u'Show my state on my profile',
		required=False,
	)

	view_country = forms.BooleanField(
		label=u'Show my country on my profile',
		required=False,
	)

	personal_statement = forms.CharField(
		widget=forms.Textarea(attrs={'rows':4, 'cols':60}),
		required=False,
	)

class JobForm(forms.Form):
	title = forms.CharField(
		label=u'Job Title',
		max_length=50,
		error_messages={'required': 'Please enter the job\'s title '},
	)

	company = forms.CharField(
		label=u'Company',
		max_length=30,
		error_messages={'required': 'Please enter your company\'s name'},
	)
		
	pay = forms.DecimalField(
		label=u'Pay',
		decimal_places=2,
		required=False,
	)
	
	description = forms.CharField(
		widget=forms.Textarea(attrs={'rows':4, 'cols':60}),
		required=False,
	)

	FullTime = forms.BooleanField(
		label=u'Full-Time',
		required=False,
	)

	PartTime = forms.BooleanField(
		label=u'Part-Time',
		required=False,
	)

	Salary = forms.BooleanField(
		label=u'Salary',
		required=False,
	)

	Hourly = forms.BooleanField(
		label=u'Hourly',
		required=False,
	)
	
class FilterForm(forms.Form):
	FullTime = forms.BooleanField(
		label=u'Full-Time',
		required=False,
	)

	PartTime = forms.BooleanField(
		label=u'Part-Time',
		required=False,
	)

	Salary = forms.BooleanField(
		label=u'Salary',
		required=False,
	)

	Hourly = forms.BooleanField(
		label=u'Hourly',
		required=False,
	)
